package com.wxmit.ot.gen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxmit.ot.base.ApiResult;
import com.wxmit.ot.base.core.OtBaseController;
import com.wxmit.ot.base.core.PageDTO;
import com.wxmit.ot.gen.constant.CodeTemplateParamConstant;
import com.wxmit.ot.gen.domain.GenGroup;
import com.wxmit.ot.gen.domain.GenGroupItem;
import com.wxmit.ot.gen.service.GenGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * GenGroupController
 * @author huangxiong
 * @version V1.0
 * @date 2023/2/22 10:50
 */
@RestController
@RequestMapping("/gen/group")
@Slf4j
public class GenGroupController extends OtBaseController<GenGroupService,GenGroup,Long> {

    public GenGroupController(GenGroupService baseService) {
        super(baseService);
    }

    @GetMapping("/items/{id}")
    public ApiResult<List<GenGroupItem>> listFileById(@PathVariable("id") Long id){
        return ApiResult.successWithData(baseService.listFileById(id));
    }

    @GetMapping("/dfVar")
    public ApiResult<Map<String,Object>> getDefVarDescription(){
        return ApiResult.successWithData(CodeTemplateParamConstant.codeTemplateParamDescribeMap);
    }

    @GetMapping("/list/option")
    public ApiResult<List<GenGroup>> listSelectOptions(){
        return ApiResult.successWithData(baseService.listSelectOptions());
    }

    @Override
    public ApiResult<Page<GenGroup>> list(PageDTO<GenGroup> pageDTO) {
        Page<GenGroup> page = new Page<>();
        List<GenGroup> genGroups = baseService.listWithItem(pageDTO.getSearchData());
        page.setTotal(genGroups.size());
        page.setRecords(genGroups);
        return ApiResult.successWithData(page);
    }

    @PostMapping("/copy/{id}")
    public ApiResult copy(@PathVariable("id") Long id){
        baseService.copy(id);
        return ApiResult.success();
    }
}
